
import React, { Component } from 'react'

import { getQuery } from "@utils/setUrlQuery";
import TimeInventory from "@components/warehouse/TimeInventory"
import InventoryRecords from "@components/warehouse/InventoryRecords"
import BrokenRecord from "@components/warehouse/BrokenRecord"
import { Tabs, Input, Button } from 'antd'
import { withRouter } from "react-router-dom";
const TabPane = Tabs.TabPane;
import BilinIcon from "@common/presentational/BilinIcon";
@withRouter
class StockManage extends Component {

    constructor(props) {
        super(props)
        const {
            activeTab = 'timeInventory',
        } = getQuery(props.history)

        this.state = {
            activeTab,
            firstRender: true
        }
        this.changeTab = this.changeTab.bind(this)
        this.goCheck = this.goCheck.bind(this)
    }

    changeTab(key) {
        this.setState({
            activeTab: key,
            firstRender: false,
        })
    }

    goCheck() {
        this.props.history.push(`/warehouse/check`)
    }

    render() {
        const { activeTab, firstRender } = this.state

        return (
            <div className='table-scroll-container stock-table'>
                <Button type="primary" className="button-small mgb-16" onClick={this.goCheck} ><BilinIcon type="plus" className="ft-18 mgr-8"/>新建盘点单</Button>
                <Tabs
                    type="card"
                    activeKey={activeTab}
                    onChange={this.changeTab}
                    className='stock-manage-tabs'
                >
                    <TabPane tab="库存查询" key="timeInventory">
                        {firstRender && activeTab !== 'timeInventory' ? null :
                            <TimeInventory
                                activity={activeTab === 'timeInventory'}
                                tab='timeInventory'
                            />
                        }
                    </TabPane>
                    <TabPane tab="盘点记录" key="inventoryRecords">
                        {firstRender && activeTab !== 'inventoryRecords' ? null :
                            <InventoryRecords
                                activity={activeTab === 'inventoryRecords'}
                                tab='inventoryRecords'
                            />
                        }
                    </TabPane>
                    <TabPane tab="报损记录" key="brokenRecord">
                        {firstRender && activeTab !== 'brokenRecord' ? null :
                            <BrokenRecord
                                activity={activeTab === 'brokenRecord'}
                                tab='brokenRecord'
                            />
                        }
                    </TabPane>
                </Tabs>
            </div>
        )
    }
}

export default StockManage